package com.wb.jar;

import android.annotation.*;
import android.net.wifi.*;
import android.app.*;
import android.provider.*;
import com.unity3d.player.*;
import com.gama.keyi.*;
import android.util.*;
import xdown.*;
import android.telephony.*;
import android.os.*;
import android.bluetooth.*;
import android.text.*;
import android.hardware.*;
import java.nio.charset.*;
import android.content.*;
import java.io.*;
import android.graphics.*;
import android.net.*;

@SuppressLint({ "NewApi" })
public class AndroidUtil
{
    public static final String DCIM_PATH;
    public static final String EXTERNAL_STORAGE_DIR;
    private static final String TAG = "MainActivity";
    public static final int VIVO_FILLET = 8;
    public static final int VIVO_NOTCH = 32;
    public static onSignalChange onChange;

    static {
        String absolutePath;
        if (Environment.getExternalStorageState().equalsIgnoreCase("mounted")) {
            absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        }
        else {
            absolutePath = "/mnt/sdcard";
        }
        EXTERNAL_STORAGE_DIR = absolutePath;
        final StringBuilder sb = new StringBuilder();
        sb.append(AndroidUtil.EXTERNAL_STORAGE_DIR);
        sb.append("/");
        sb.append(Environment.DIRECTORY_DCIM);
        sb.append("/");
        DCIM_PATH = sb.toString();
    }

    public static String GetMac(final Context context) {
        if (context == null) {
            return "";
        }
        final WifiManager wifiManager = (WifiManager)context.getSystemService("wifi");
        WifiInfo connectionInfo;
        try {
            connectionInfo = wifiManager.getConnectionInfo();
        }
        catch (Exception ex) {
            ex.printStackTrace();
            connectionInfo = null;
        }
        if (connectionInfo == null) {
            return null;
        }
        return connectionInfo.getMacAddress();
    }

    public static boolean IsNotchScreen(final Activity activity) {
        final int int1 = getInt("ro.miui.notch", activity);
        boolean b2;
        final boolean b = b2 = true;
        if (int1 != 1) {
            b2 = b;
            if (!hasNotchAtHuawei((Context)activity)) {
                b2 = b;
                if (!hasNotchAtOPPO(activity.getApplicationContext())) {
                    if (hasNotchAtVivo((Context)activity)) {
                        return true;
                    }
                    b2 = false;
                }
            }
        }
        return b2;
    }

    public static boolean IsSimulator(final Context context) {
        return notHasBlueTooth() || notHasLightSensorManager(context) || isFeatures() || checkIsNotRealPhone();
    }

    public static void OpenAlbum() {
        Intent intent;
        if (Build.VERSION.SDK_INT < 19) {
            intent = new Intent("android.intent.action.GET_CONTENT");
            intent.setType("image/*");
        }
        else {
            intent = new Intent("android.intent.action.PICK", MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        }
        UnityPlayer.currentActivity.startActivityForResult(intent, 1);
    }

    public static void XdownDestroy() {
        if (UnityPlayerActivity.xDownThread.isAlive()) {
            Log.e("==btnTerminal", "onDestroy!!!");
            Xdown.onDestroy();
        }
    }

    public static boolean checkIsNotRealPhone() {
        final String cpuInfo = readCpuInfo();
        return cpuInfo.contains("intel") || cpuInfo.contains("amd");
    }

    public static int getInt(final String s, final Activity activity) {
        if (isXiaomi()) {
            try {
                final Class<?> loadClass = activity.getClassLoader().loadClass("android.os.SystemProperties");
                return (int)loadClass.getMethod("getInt", String.class, Integer.TYPE).invoke(loadClass, s, 0);
            }
            catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return 0;
    }

    public static void getPhoneSigal() {
        ((TelephonyManager)UnityPlayer.currentActivity.getSystemService("phone")).listen((PhoneStateListener)new PhoneStateListener() {
            public void onSignalStrengthsChanged(final SignalStrength signalStrength) {
                final int level = signalStrength.getLevel();
                if (AndroidUtil.onChange != null) {
                    AndroidUtil.onChange.onValueChange(level);
                }
            }
        }, 256);
    }

    public static boolean hasNotchAtHuawei(final Context context) {
        try {
            final Class<?> loadClass = context.getClassLoader().loadClass("com.huawei.android.util.HwNotchSizeUtil");
            return (boolean)loadClass.getMethod("hasNotchInScreen", (Class<?>[])new Class[0]).invoke(loadClass, new Object[0]);
        }
        catch (Exception ex) {}
        finally {
            return false;
        }
    }

    public static boolean hasNotchAtOPPO(final Context context) {
        return context.getPackageManager().hasSystemFeature("com.oppo.feature.screen.heteromorphism");
    }

    public static boolean hasNotchAtVivo(final Context context) {
        try {
            final Class<?> loadClass = context.getClassLoader().loadClass("android.util.FtFeature");
            return (boolean)loadClass.getMethod("isFeatureSupport", Integer.TYPE).invoke(loadClass, 32);
        }
        catch (Exception ex) {}
        finally {
            return false;
        }
    }

    public static boolean isFeatures() {
        return Build.FINGERPRINT.startsWith("generic") || Build.FINGERPRINT.toLowerCase().contains("vbox") || Build.FINGERPRINT.toLowerCase().contains("test-keys") || Build.MODEL.contains("google_sdk") || Build.MODEL.contains("Emulator") || Build.MODEL.contains("Android SDK built for x86") || Build.MANUFACTURER.contains("Genymotion") || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) || "google_sdk".equals(Build.PRODUCT);
    }

    public static boolean isXiaomi() {
        return "Xiaomi".equals(Build.MANUFACTURER);
    }

    public static boolean notHasBlueTooth() {
        final BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
        return defaultAdapter == null || TextUtils.isEmpty((CharSequence)defaultAdapter.getName());
    }

    public static Boolean notHasLightSensorManager(final Context context) {
        return ((SensorManager)context.getSystemService("sensor")).getDefaultSensor(5) == null;
    }

    public static String readCpuInfo() {
        try {
            final Process start = new ProcessBuilder(new String[] { "/system/bin/cat", "/proc/cpuinfo" }).start();
            final StringBuffer sb = new StringBuffer();
            final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(start.getInputStream(), StandardCharsets.UTF_8));
            while (true) {
                final String line = bufferedReader.readLine();
                if (line == null) {
                    break;
                }
                sb.append(line);
            }
            bufferedReader.close();
            return sb.toString().toLowerCase();
        }
        catch (IOException ex) {
            return "";
        }
    }

    public static void registerBatteryReceiver() {
        UnityPlayer.currentActivity.registerReceiver((BroadcastReceiver)new BatteryReceiver(), new IntentFilter("android.intent.action.BATTERY_CHANGED"));
    }

    public static String savePictureToDCIM(final String s, String string, final String s2) throws IOException {
        final StringBuilder sb = new StringBuilder();
        sb.append(AndroidUtil.DCIM_PATH);
        sb.append(string);
        string = sb.toString();
        final File file = new File(string);
        if (!file.exists()) {
            file.mkdirs();
        }
        final File file2 = new File(string, s2);
        if (!file2.exists()) {
            file2.createNewFile();
        }
        final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file2));
        BitmapFactory.decodeFile(s).compress(Bitmap.CompressFormat.JPEG, 80, (OutputStream)bufferedOutputStream);
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
        final Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
        intent.setData(Uri.fromFile(file2));
        UnityPlayer.currentActivity.sendBroadcast(intent);
        final StringBuilder sb2 = new StringBuilder(string);
        sb2.append("/");
        sb2.append(s2);
        return sb2.toString();
    }

    public static void setOnChange(final onSignalChange onChange) {
        AndroidUtil.onChange = onChange;
    }
}
